﻿// -----------------------------------------------------------------------
// <copyright file="AlienShip.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SpaceshipDuel
{
    /// <summary>
    /// Alienraumschiff Basisklasse
    /// </summary>
    public class AlienShip : GameObject
    {
        #region Private fields

        protected TextureData shotTextureData;// Textur für Schüsse

        protected int bulletCount;            // aktuelle Schussanzahl
        protected int maxBulletCount;         // maximale Schussanzahl
        protected int maxBulletDistance;      // Flugweite der Schüsse
        protected int shieldPower;            // Schildstärke (="Gesundheit")
        protected int maxShieldPower;         // maximale Schildstärke

        protected float bulletSpeed;          // Geschwindigkeit der Schüsse
        protected float rotation;             // Wert der Rotationsänderung
        protected float speed;                // Wert der Geschwindigkeitsänderung
        protected float rotate_speed;         // Rotationsgeschwindigkeit
        protected float nextBulletInterval;   // Intervall zwischen den Schüssen
        protected float rotationAngle;        // Rotationswinkel des Raumschiffs

        protected Vector2 velocity;           // Geschwindigkeitsvektor
        protected WaitTimer nextBulletTimer;  // Timer für Schussintervall
        protected List<Bullet> bullets;       // Refernz auf Geschossliste

        // Dividenten für Winkel bei Annäherungsstufen
        protected const int F0 = 20;
        protected const int F1 = 30;
        protected const int F2 = 40;
        protected const int F3 = 50;
        protected const int F4 = 60;
        protected const int F5 = 70;

        // Dividenten für Geschwindigkeiten bei Annäherungsstufen
        protected const float V1 = 2.0f;
        protected const float V2 = 1.8f;
        protected const float V3 = 1.6f;
        protected const float V4 = 1.4f;
        protected const float V5 = 1.2f;

        #endregion Private fields

        #region Public properties

        public float RotationAngle
        {
            get { return this.rotationAngle; }
            set { this.rotationAngle = value; }
        }

        public int ShieldPower
        {
            get { return this.shieldPower; }
            set { this.shieldPower = value; }
        }

        public Vector2 Velocity
        {
            get { return this.velocity; }
            set { this.velocity = value; }
        }

        public int MaxBulletDistance
        {
            get { return this.maxBulletDistance; }
            set { this.maxBulletDistance = value; }
        }

        public int MaxShieldPower
        {
            get { return this.maxShieldPower; }
            set { this.maxShieldPower = value; }
        }

        public int Radius
        {
            get { return textureData.halfheight; }
        }

        #endregion Public properties

        #region Construction

        #endregion Construction

        #region Public methods

        /// <summary>
        /// Draw-Methode
        /// </summary>
        new public void Draw(SpriteBatch spriteBatch, float xOffset, float yOffset)
        {
            spriteBatch.Draw(textureData.texture, new Vector2(center.X + xOffset, center.Y + yOffset), new Rectangle(0, 0, textureData.width, textureData.height), Color.White, rotationAngle, new Vector2(textureData.halfwidth, textureData.halfheight), 1.0f, SpriteEffects.None, 0f);
        }

        /// <summary>
        /// Schiff wurde getroffen, Gesundheit wird verringert
        /// </summary>
        /// <param name="damage">Schaden, den das Schiff abbekommen hat</param>
        public void Hit(int damage = 1)
        {
            shieldPower -= damage;
        }

        #endregion Public methods

        #region Protected methods

        /// <summary>
        /// Korrektur der Schiffsposition beim Flug über Spielfeldgrenzen hinweg
        /// </summary>
        protected void CheckPosition()
        {
            if (center.X < 0)
                center.X = worldSize + center.X;
            else if (center.X >= worldSize)
                center.X = center.X - worldSize;

            if (center.Y < 0)
                center.Y = worldSize + center.Y;
            else if (center.Y >= worldSize)
                center.Y = center.Y - worldSize;
        }

        #endregion Private methods
    }
}
